package fun.qu_an.minecraft.fabric.fzbbl.handle;

import fun.qu_an.minecraft.fabric.fzbbl.FZBBL;
import net.minecraft.scoreboard.ScoreboardCriterion;
import net.minecraft.scoreboard.ScoreboardObjective;

public class ScoreboardAddedHandle {
    public static void handle(ScoreboardObjective objective) {
        String name = objective.getName();
        if (objective.getCriterion() != ScoreboardCriterion.DUMMY) return;

        int i = name.length() - 4;
        if (i < 0) return;
        String suffix = name.substring(i);

        // 判断计分板名字后四位是不是“.bbl”或“.mbb”，是的话把它加到列表里
        // 在服务器初始化时会为每个记分板调用这个方法(Scoreboard.addObjective())，因此不用单独在初始化完成后获取记分板
        switch (suffix) {
            case ".bbl" -> {
                FZBBL.BBL.add(objective);
                // 日志
                FZBBL.LOGGER.debug("ScoreboardAdded: {}", name);
            }
            case ".mbb" -> {
                FZBBL.MBB.add(objective);
                // 日志
                FZBBL.LOGGER.debug("ScoreboardAdded: {}", name);
            }
            case ".lbl" -> {
                FZBBL.LBL.add(objective);
                // 日志
                FZBBL.LOGGER.debug("ScoreboardAdded: {}", name);
            }
        }
    }
}
